import { Plugin } from 'vite'
import fs from 'fs'
import path from 'path'

const data = fs.readFileSync(path.resolve(__dirname, '../src/assets/scss/main.scss'))

const content = data.toString()
const match = content.match(/--el-color-primary: (\S*);/);
let color = ''
if (match) {
    // name = match[1]
    color = match[1]
}
// console.log('data', data.toString());

export default function TranslateLineColor(): Plugin {
    return {
        name: 'TranslateLineColor',
        transform: (code, _id, _opt) => {
            return code.replace(/\$primary--color/g, color)
        }
    }
}